#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from tkinter import *           # 导入 Tkinter 库
from tkinter.scrolledtext import *
# import tkinter
import random

root = Tk()  # 创建主窗口对象

# root 下增加一个文本框
text = ScrolledText(root) # 新建-停靠
text.pack()

# root 下增加一个单行文本框
entry = Entry(root) # 新建-停靠
entry.pack()

greetings = ['Hello world', 'I love you', 'blahblahblah']

def greet():
    # 命令：无参数函数
    # "Hello world" 插入到文本框text当前位置
    s = random.choice(greetings)
    text.insert(CURRENT, s+'\n')

def clear():
    text.delete('0.0', 'end')

def read():
    s = entry.get()        # 读入字符串
    text.insert(CURRENT, s+'\n') # 显示字符串

button_greet = Button(root, text="Greet", command=greet)
button_greet.pack()

button_read = Button(root, text="Read", command=read)
button_read.pack()

button_clear = Button(root, text="Clear", command=clear)
button_clear.pack()

root.mainloop()
